package com.yh.correct.service.impl;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yh.correct.dao.IThoughtMapper;
import com.yh.correct.model.Page;
import com.yh.correct.model.Project;
import com.yh.correct.model.Thought;
import com.yh.correct.service.IThoughtService;

/**
 * 思想教育业务实现类
 * 
 * @author 陈帅
 *
 */


@Service
public class ThoughtServiceImpl implements IThoughtService{

	private static Logger logger= LogManager.getLogger(ThoughtServiceImpl.class);
	
	@Autowired
	private IThoughtMapper thoughtMapper;

	/**
	 *根据id查询思想教育方案
	 * @throws Exception 
	 */
	@Override
	public Map<String,Object> getThought(Thought t) throws Exception {
		// TODO Auto-generated method stub
		Map<String,Object> map=null;
		map=thoughtMapper.getThought(t);
		return map;
	}

	/**
	 *添加思想教育方案
	 * @throws Exception 
	 */
	@Override
	public int addThought(Thought t) throws Exception {
		// TODO Auto-generated method stub
		logger.error("添加思想教育："+t);
		return thoughtMapper.addThought(t);
	}

	/**
	 *删除思想教育方案
	 * @throws Exception 
	 */
	@Override
	public int delThought(Thought t) throws Exception {
		// TODO Auto-generated method stub
		return thoughtMapper.delThought(t);
	}
	
	/**
	 *修改思想教育方案
	 * @throws Exception 
	 */
	
	@Override
	public int editThought(Thought t) throws Exception {
		// TODO Auto-generated method stub
		return thoughtMapper.editThought(t);
	}

	/**
	 *根据姓名,日期模糊查询思想教育方案
	 * @throws Exception 
	 */
	@Override
	public Page getLikeThoughts(Map<String, Object> condition) throws Exception {
		Page page=new Page();
		page.setTotalNum(thoughtMapper.getLikeThoughtsCount(condition));
		int pageSize = Integer.parseInt(String.valueOf(condition.get("pageSize")));
		page.setPageSize(pageSize);
		int curPageNum = Integer.parseInt(String.valueOf(condition.get("pageNum")));
		page.setCurPageNum(curPageNum);
		page.setTotalPage(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize==0?0:1));
		page.setResult(thoughtMapper.getLikeThoughts(condition));
		logger.debug("模糊查询思想教育方案!");
		return page;
   }
	
	/**
	 * 获取所有记录,导出excel
	 * @return
	 * @throws Exception 
	 */
	@Override
	public List<Map<String, Object>> getAllT() throws Exception {
		// TODO Auto-generated method stub
		return thoughtMapper.getAllT();
	}
}
